package com.ruoyi.standingbook.extermination.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.standingbook.extermination.domain.bo.ExterminationBo;
import com.ruoyi.standingbook.extermination.domain.vo.ExterminationPicVo;
import com.ruoyi.standingbook.extermination.domain.vo.ExterminationVo;
import com.ruoyi.standingbook.extermination.service.IExterminationService;
import com.ruoyi.standingbook.extermination.service.impl.ExterminationExcelService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 四害消杀
 *
 * @author cc
 * @date 2023-04-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/standingbook/extermination")
public class ExterminationController extends BaseController {

    private final IExterminationService iExterminationService;

    private final ExterminationExcelService exterminationExcelService;

    /**
     * 查询四害消杀列表
     */
    @SaCheckPermission("standingbook:extermination:list")
    @GetMapping("/list")
    public TableDataInfo<ExterminationVo> list(ExterminationBo bo, PageQuery pageQuery) {
        return iExterminationService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出四害消杀列表
     */
    @SaCheckPermission("standingbook:extermination:export")
    @Log(title = "四害消杀", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ExterminationBo bo, HttpServletResponse response) {
        List<ExterminationVo> list = iExterminationService.queryList(bo);
        ExcelUtil.exportExcel(list, "四害消杀", ExterminationVo.class, response);
    }

    /**
     * 导出四害消杀日报
     */
    @SaCheckPermission("standingbook:sorting:export")
    @Log(title = "垃圾分类督导", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDailyReport")
    public void exportDailyReport(ExterminationBo bo, HttpServletResponse response) {
        exterminationExcelService.exportDailyReport(bo,response);
    }

    /**
     * 获取四害消杀详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("standingbook:extermination:query")
    @GetMapping("/{id}")
    public R<ExterminationVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iExterminationService.queryById(id));
    }

    /**
     * 新增四害消杀
     */
    @SaCheckPermission("standingbook:extermination:add")
    @Log(title = "四害消杀", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ExterminationBo bo) {
        return toAjax(iExterminationService.insertByBo(bo));
    }

    /**
     * 修改四害消杀
     */
    @SaCheckPermission("standingbook:extermination:edit")
    @Log(title = "四害消杀", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ExterminationBo bo) {
        return toAjax(iExterminationService.updateByBo(bo));
    }

    /**
     * 删除四害消杀
     *
     * @param ids 主键串
     */
    @SaCheckPermission("standingbook:extermination:remove")
    @Log(title = "四害消杀", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iExterminationService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 按指定日期查询智慧大屏四害消杀台账
     * @param date 指定日期
     * @return
     */
    @SaIgnore()
    @GetMapping("/exterminationByDate")
    public R<List<ExterminationVo>> exterminationByDate(String date) {
        return R.ok(iExterminationService.queryListByDate(date));
    }

    @SaIgnore()
    @GetMapping("/drugPic")
    public R<List<ExterminationPicVo>> drugPic(String date)  {
        return R.ok(iExterminationService.getDrugPicByDate(date));
    }

    @SaIgnore()
    @GetMapping("/beforePic")
    public R<List<ExterminationPicVo>> beforePic(String date)  {
        return R.ok(iExterminationService.getBeforePicByDate(date));
    }

    @SaIgnore()
    @GetMapping("/coursePic")
    public R<List<ExterminationPicVo>> coursePic(String date)  {
        return R.ok(iExterminationService.getCoursePicByDate(date));
    }

    @SaIgnore()
    @GetMapping("/afterPic")
    public R<List<ExterminationPicVo>> afterPic(String date)  {
        return R.ok(iExterminationService.getAfterPicByDate(date));
    }
}
